package com.upstairstechnology.oi.determination;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Processes output lines from the executed command results.
 * 
 * @author Jeff Jensen
 */
public interface CommandReader {
    /**
     * Setup the input stream as needed for use.
     * 
     * @param is
     *            InputStream to wrap in a BufferedReader.
     * @return BufferedReader to use.
     */
    BufferedReader setupIn(InputStream is);

    /**
     * Read the next line of output from the issued command.
     * 
     * @param command
     *            Issued program and its arguments; typically used only in error
     *            messages.
     * @param inStd
     *            Standard input to read the next line from.
     * @param inErr
     *            Error input to read error messages from. If inErr has
     *            messages, typical implementations will invoke error handling.
     * @return Next line read from inStd.
     * @throws IOException
     *             When problems occur with reading the line.
     */
    String readNextLine(List<String> command, BufferedReader inStd,
            BufferedReader inErr) throws IOException;

    /**
     * Get the error handler.
     * 
     * @return The error handler.
     */
    CommandReaderErrorHandler getErrorHandler();

    /**
     * Set the error handler.
     * 
     * @param handler
     *            The error handler.
     */
    void setErrorHandler(CommandReaderErrorHandler handler);
}
